package com.example.demo.config;

import com.example.demo.common.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

// 统一异常返回, 未被捕获处理的异常, 在这里统一进行处理
@ControllerAdvice
public class ErrorAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResult handler(Exception e) {
        return JsonResult.failure(500, e.getMessage());
    }
}
